package com.wd.buycar.view.fragment

import android.R
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.wd.buycar.databinding.FragmentBuyBinding
import com.wd.common.base.BaseFragment


class BuyFragment : BaseFragment<FragmentBuyBinding>() {
    override fun getViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentBuyBinding =FragmentBuyBinding.inflate(layoutInflater)
    private val title = arrayOf("新车", "二手车")

    override fun initData() {
        val fragments = ArrayList<Fragment>()
        fragments.add(BuyNewCarFragment())
        fragments.add(BuyOldCarFragment())
        binding.buyViewpageid.offscreenPageLimit = 2

        binding.buyViewpageid.adapter = object : FragmentPagerAdapter(childFragmentManager) {
            override fun getItem(position: Int): Fragment {
                return fragments[position]
            }

            override fun getCount(): Int {
                return fragments.size
            }

            override fun getPageTitle(position: Int): CharSequence? {
                return title[position]
            }

        }
        //指示器颜色
        binding.buyTabid.setSelectedTabIndicatorColor(resources.getColor(R.color.white))
        binding.buyTabid.setupWithViewPager(binding.buyViewpageid)
        binding.buyTabid.getTabAt(0)?.select()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        binding.buyViewpageid.removeAllViews()

    }
}